package com.fss.order.controller;

import com.fss.common.core.controller.BaseController;
import com.fss.order.domain.Order;
import com.fss.order.impl.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/order")
public class OrderController extends BaseController
{
 @Autowired
    private OrderService orderService;

 // 创建订单
    @PostMapping("/insertOrder")
    public String createOrder(@RequestBody Order order) {
        orderService.createOrder(order);
        return "Order created successfully!";
    }

    // 根据 userId 查询订单
    @GetMapping("/getOrderByUserId/{userId}")
    public List<Order> getOrderByUserId(@PathVariable Long userId) {
        return orderService.getOrderByUserId(userId);
    }
    /**
     * 删除订单及其详情
     * @param orderId 要删除的订单ID
     * @return 删除结果
     */
    @DeleteMapping("/deleteOrder/{orderId}")
    public String deleteOrder(@PathVariable Long orderId) {
        int isDeleted = orderService.deleteOrderById(orderId);

        if (isDeleted==1) {
            return "订单删除成功";
        } else {
            return "订单删除失败";
        }
    }
}
